package com.java.base.exercise.proxy.dynamicproxy;

import org.springframework.aop.interceptor.PerformanceMonitorInterceptor;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Objects;

/**
 * @Author RenPu
 * @Date 2022/1/5 11:54
 * @Version 1.0
 * @Description:
 **/
public class JDKDynamicInvocationHandler implements InvocationHandler {

    private Object target;

    public JDKDynamicInvocationHandler(Object target) {
        super();
        this.target = target;
    }

    @Override
    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {

        System.out.println(target.getClass().getName()+"-----------"+method.getName());

        Object invoke = method.invoke(target, objects);
        System.out.println("JDK"+invoke);

        System.out.println("结束........................");

        return invoke;
    }

    public Object getProxy(){

        return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),target.getClass().getInterfaces(),this);
    }


}
